using UnityEngine;

namespace PKGames.MiniGames.Common.Scripts
{
	public abstract class UiStateController<TEnum> : MonoBehaviour
	{
		private TEnum _uiState;

		protected TEnum UiState => _uiState;

		protected void TryChangingToNextState(TEnum nextState)
		{
			if (CanChangeToNextState(nextState))
			{
				ChangeToNextState(nextState);
			}
		}

		protected abstract bool CanChangeToNextState(TEnum nextState);

		protected void ChangeToNextState(TEnum nextState)
		{
			_uiState = nextState;
			UpdateUiAccordingToState(nextState);
		}

		protected abstract void UpdateUiAccordingToState(TEnum nextState);
	}
}
